package com.doge.walknovel.utils

import com.doge.walknovel.api.ApiResultComposeTransformer
import com.doge.walknovel.api.ObserverAdapter
import com.doge.walknovel.api.api
import com.doge.walknovel.api.subscribeOnIO


fun feedback(type: String, title: String, remark: String, retry: Int = 0) {
    log("feedback type $type title $title remark $remark retry $retry")
    api
        .feedback(type, title, remark)
        .compose(ApiResultComposeTransformer())
        .subscribeOnIO()
        .subscribe(object : ObserverAdapter<Any?>() {
            override fun onError(e: Throwable) {
                if (retry > 0) {
                    delay(3000) { feedback(type, title, remark, retry - 1) }
                }
            }
        })
}